<?php 
class BackupController extends Controller{
    /**
     * 备份列表
     */
    public function index(){
		//显示备份的目录
    		$dirs = Dir::tree('Backup');
		$this->assign('dirs',$dirs);
		$this->display(); 
    }
	
	/**
	 * 备份动作
	 */
	public function backup(){
		$result = Backup::backup(
			array(
				'size' => 200,// 分卷大小
				'dir' => 'Backup/' . date("Ymdhis") . '/',// 备份目录
				'step_time' => 1,// 备份时间间隔
			)
		);
		//如果备份失败
		if ($result === false) {
			$this->error(Backup::$error, U('Index/welcome'));
		}else{
			//如果备份成功
			if ($result['status'] == 'success') {
				$this->success($result['message'], U('index'));
			}else{//如果在备份的过程中
				$this->success($result['message'], $result['url'], 0.2);
			}
		}
	}
	
	public function recovery(){
		$dir = Q('post.dir');
		//如果不存在session里面的dir,则存入
		if(!isset($_SESSION['dir'])){
			$_SESSION['dir'] = $dir;
		}
		//数据还原
		$result = Backup::recovery(array('dir' => $_SESSION['dir']));
		if ($result === false) {
			// 还原发生错误
			$this->error(Backup::$error, U('Index/welcome'));
		}else{
			if ($result['status'] == 'success') {
				unset($_SESSION['dir']);
				// 还原完毕
				$this->success($result['message'], U('index'));
			}else{
				// 还原运行中 ...
				$this->success($result['message'], $result['url'], 0.2);
			}
		}
	}
 }
 
 
 
 
 
 
 
 
 
 
 



 ?>